package com.alen.sun.dao;

import com.alen.sun.bean.Admin;
import com.alen.sun.bean.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {
    //添加管理员
    @Insert("INSERT INTO admin (adminId, name, phoneNum, password) VALUES (#{adminId}, #{name}, #{phoneNum}, #{password})")
    Boolean addAdmin(Admin admin);

    //修改管理员
    @Update("UPDATE admin SET name = #{name} , phoneNum = #{phoneNum} , password = #{password} WHERE adminId = #{adminId}")
    Boolean updateAdmin(Admin admin);

    //删除管理员
    @Delete("DELETE FROM admin WHERE adminId = #{adminId}")
    Boolean deleteAdmin(Admin admin);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from admin")
    Long count();

    /**
     * 分页查询,获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from admin limit #{start},#{pageSize}")
    List<Admin> page(Integer start, Integer pageSize);

    //批量删除
    @Delete({
            "<script>",
            "delete from admin where adminId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);

    //查找管理员根据phoneNum
    @Select("SELECT count(*) FROM admin WHERE phoneNum = #{phoneNum}")
    Integer selectByPhoneNum(Admin admin);

    //查找管理员根据adminId
    @Select("SELECT count(*) FROM admin WHERE adminId = #{adminId}")
    Integer selectByAdminId(String adminId);

    //根据phoneNum查找到记录
    @Select("SELECT * FROM admin WHERE phoneNum = #{phoneNum}")
    Admin selectPhoneNum(Admin admin);
}
